package com.kinglone.back.user.service.impl;

import com.kinglone.back.user.dao.UserMapper;
import com.kinglone.back.user.model.User;
import com.kinglone.back.user.service.UserService;
import org.apache.shiro.authc.AccountException;
import org.apache.shiro.authc.DisabledAccountException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("userService")
public class UserServiceImpl implements UserService {
	
	@Resource
	private UserMapper userMapper;

	@Override
	public User login(String account, String password) {
		Map<String,Object> params = new HashMap<String, Object>();
		params.put("account",account);
		params.put("password",password);

		User user = userMapper.login(params);
		if(null==user){
			throw new AccountException("帐号或密码不正确！");
		}
		if("1".equals(user.getIsDisabled())){
			throw new DisabledAccountException("帐号已经禁止登录！");
		}
		return user;
	}

    @Override
    public List<User> list(Map<String, Object> map) {
        return userMapper.list(map);
    }

	@Override
	public int getTotal(Map<String, Object> map) {
		return userMapper.getTotal(map);
	}

    @Override
    public User selectById(String userId) {
        return userMapper.selectById(userId);
    }

	@Override
	public void setRoles(Integer userId, String roleIds) {
		userMapper.setRoles(userId,roleIds);
	}

	@Override
	public User getUserByAccount(String account) {
		return userMapper.getUserByAccount(account);
	}



}
